<template>

	<div id="user-profile">
		<van-form @submit="onSubmit">
			<van-field label="姓名" v-model="contactForm.name" type="text" placeholder="请输入名字"
				:rules="[{ pattern:regNamePwd,required: true, message: '无效名字' }]" />
			<van-field label="问题" v-model="contactForm.help" type="text" placeholder="请输入问题"
				:rules="[{ pattern:regNamePwd,required: true, message: '无效问题' }]" />

			<van-field label="详情" v-model="contactForm.contactDetail" type="text" placeholder="请输入详情"
				:rules="[{ pattern:regEmail, message: '请详细' }]" />

			<van-field label="邮箱" v-model="contactForm.email" type="text" placeholder="请输入邮箱"
				:rules="[{ pattern:regPhone, message: '无效邮箱' }]" />
		</van-form>
	</div>
</template>
<script>
	import {
		getContactEditByIdAPI
	} from "@/api/contact.js";

	import * as Auth from "@/utils/auth.js"; //本地存储数据
	
	export default {
		data() {
			return {
				contactForm: {
					id: "", 
					name: "", 
					help: "", 
					cantactDetail: "", 
					email: "", 
				}
			};
		},

		props: ["id"],

		created() {
			this.getContactDetail();

		},
		methods: {
			getContactDetail() {
				if (this.id) {
					getContactEditByIdAPI(this.id).then(result => {
						this.contactForm.id = result.data.id;
						this.contactForm.name = result.data.name;
						this.contactForm.help = result.data.help;
						this.contactForm.contactDetail = result.data.contact_detail; //
						this.contactForm.email = result.data.email;
					});
				}
			},
			onSubmit() {
				let contact = this.contactForm;
				updateAPI(contact).then(() => {
					this.$toast("更新成功！");
						setTimeout(() => {
							this.$router.go(-1);
						}, 10);
				});
			},
		},
	};
</script>

<style>

</style>
